package util;

import java.util.ArrayList;
import java.util.List;

import entity.Protein;

public class UniprotParserUtil {
	/**
	 * Parses search results in a file downloaded in tabular from the Uniprot search page 
	 * @param contents of the file with search results  
	 * @return
	 */
	public static List<Protein> parseSearchResults(String contents) {
		List<Protein> proteins = new ArrayList<Protein>();
		String[] lines = contents.split("\n");
		for (int i=1; i<lines.length; i++) {
			String[] cells = lines[i].split("\\t");  
			Protein p = new Protein();
			p.setEntry(cells[0]);
			p.setEntryName(cells[1]);
			p.setReviewed("reviewed".equals(cells[2]));
			p.setProteinNames(cells[3]);
			p.setGeneNames(cells[4]);
			p.setOrganism(cells[5]);
			p.setLength(Integer.parseInt(cells[6]));
			proteins.add(p);
		}
		return proteins;
	}
}


